import sys

tmax=0
tstart=-1
tend=-1

fmax=0
fstart=-1
fend=-1


def cmpMax(left, right):
    if left >= right:
        return left, False
    return right, True

###需要先去掉前面小于等于0的值后，再调用该方法。
def method5(list):
    global tmax
    global fmax
    global tstart
    global tend
    global fstart
    global fend

    tmax=0
    tstart=0
    tend=0


    fmax=0
    fstart=0
    fend=0
    
    for i in range(len(list)):
        fmax, isSwitchMiddle = cmpMax(fmax+x[i],0)
        fend=i
        if isSwitchMiddle:
            #重新计算中间值            
            fstart=i+1            
        
        tmax, isSwitch = cmpMax(tmax,fmax)
        if isSwitch:
            tstart=fstart
            tend=fend


if __name__ == '__main__':     
    x=[31,-41,59,26,-53,58,97,-93,-23,84]     
    method5(x)
    print("%s, %s----%s" %(tmax, tstart, tend) )

    x=[1.5, -12.3, 3.2, -5.5, 23.2, 3.2, -1.4, -12.2, 34.2, 5.4, -7.8, 1.1, -4.9]
    method5(x)
    print("%s, %s----%s" %(tmax, tstart, tend) )

    
    x=[1.5, -12.3, 3.2, -5.5, 23.2, 3.2, -1.4, -62.2, 44.2, 5.4, -7.8, 1.1, -4.9]
    method5(x)
    print("%s, %s----%s" %(tmax, tstart, tend) )

